using System.Collections.Generic;

namespace PKGames.Localization
{
	public sealed class Language : TypeSafeEnum
	{
		public enum LanguageEnum
		{
			English,
			Portuguese
		}

		public static readonly Language English = new Language(0, "en", "en-US");

		public static readonly Language Portuguese = new Language(1, "pt", "pt-BR");

		private string _culture;

		private static Dictionary<string, Language> _dictionary = new Dictionary<string, Language>
		{
			{
				English.ToString(),
				English
			},
			{
				Portuguese.ToString(),
				Portuguese
			}
		};

		private static readonly Language[] _array = new Language[2]
		{
			English,
			Portuguese
		};

		public string Culture => _culture;

		public static Language[] Elements => _array;

		private Language(int value, string name, string culture)
			: base(value, name)
		{
			_culture = culture;
		}

		public static Language FromString(string name)
		{
			if (_dictionary.ContainsKey(name))
			{
				return _dictionary[name];
			}
			return English;
		}

		public static Language FromInt(int value)
		{
			if (_array.Length > value)
			{
				return _array[value];
			}
			return English;
		}

		public static string GetLanguage(Language languague)
		{
			if (languague.ToString() == English.ToString())
			{
				return "English";
			}
			if (languague.ToString() == Portuguese.ToString())
			{
				return "Portuguese";
			}
			return string.Empty;
		}
	}
}
